<?php

namespace app\admin\model;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use support\Model;

/**
 * 角色菜单关联模型
 * @property int $id
 * @property int $role_id 角色ID
 * @property int $menu_id 菜单ID
 * @property string $create_time 创建时间
 */
class RoleMenu extends Model
{
    /**
     * The table associated with the model.
     * @var string
     */
    protected $table = 'role_menu';
    /**
     * The primary key associated with the table.
     * @var string
     */
    protected $primaryKey = 'id';
    /**
     * Indicates if the model should be timestamped.
     * @var bool
     */
    public $timestamps = true;
    /**
     * The name of the "created at" column.
     * @var string|null
     */
    const CREATED_AT = 'create_time';
    /**
     * The name of the "updated at" column.
     * @var string|null
     */
    const UPDATED_AT = null;
    /**
     * The attributes that are mass assignable.
     * @var array
     */
    protected $fillable = [
        'role_id',
        'menu_id',
    ];
    /**
     * The attributes that should be cast to native types.
     * @var array
     */
    protected $casts = [
        'role_id' => 'integer',
        'menu_id' => 'integer',
        'create_time' => 'datetime:Y-m-d H:i:s',
    ];

    /**
     * 获取关联的角色
     */
    public function role(): BelongsTo
    {
        return $this->belongsTo(Role::class, 'role_id');
    }

    /**
     * 获取关联的菜单
     */
    public function menu(): BelongsTo
    {
        return $this->belongsTo(Menu::class, 'menu_id');
    }
}
